package com.yunxi.service.localService.impl.sto;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yunxi.core.page.PageHelperPlus;
import com.yunxi.core.service.ServiceImplPlus;
import com.yunxi.core.util.BeanTools;
import com.yunxi.dao.sto.VehicleOfflineMapper;
import com.yunxi.model.sto.VehicleOffline;
import com.yunxi.otd.pojo.VehicleCanChangePlanQueryVO;
import com.yunxi.otd.pojo.VehicleCanChangePlanVO;
import com.yunxi.service.localService.sto.VehicleOfflineService;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.yunxi.sto.pojo.VehicleOfflineShareReqVO;
import com.yunxi.sto.pojo.VehicleOfflineShareRespVO;
import com.yunxi.sto.pojo.VehicleOfflineVO;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

/**
 * <p>
 * 车辆下线数据 服务实现类
 * </p>
 *
 * @author caoYong
 * @since 2019-05-21
 */
@Service
public class VehicleOfflineServiceImpl extends ServiceImplPlus<VehicleOfflineMapper, VehicleOffline> implements VehicleOfflineService {

    /**
     * 车辆生产信息跟踪
     * @param map
     */
    @Override
    public void updateCarTraceInfo(Map<String, Object> map) {
        baseMapper.updateCarTraceInfo(map);
    }

    @Override
    public VehicleOffline selectCarByPlanNo(String planNo) {
        return baseMapper.selectCarByPlanNo(planNo);
    }

    @Override
    public VehicleOffline selectCarByVin(String vin) {
        return baseMapper.selectCarByVin(vin);
    }

    @Override
    public PageInfo selectCanChangePlan(VehicleCanChangePlanQueryVO queryVO, Integer pageNum, Integer pageSize) {
        Map map = BeanTools.bean2map(queryVO);
        PageHelperPlus.startPage(pageNum,pageSize);
        List<VehicleCanChangePlanVO> list = baseMapper.selectCanChangePlan(map);
        PageInfo<VehicleCanChangePlanVO> pageInfo = new PageInfo<VehicleCanChangePlanVO>(list);
        return pageInfo;
    }

    @Override
    public VehicleCanChangePlanVO selectCanChangePlanByPlanNo(String planNo) {
        Map<String, Object> map = new HashMap<>();
        map.put("planNo", planNo);
        List<VehicleCanChangePlanVO> list = baseMapper.selectCanChangePlan(map);
        return CollectionUtils.isEmpty(list) ? null : list.get(0);
    }

    /**
     * 通过主键id获取详情
     * @param id
     * @return
     */
    @Override
    public VehicleOfflineVO getDetailById(String id) {
        return baseMapper.getDetailById(id);
    }

    @Override
    public void updateByVin(VehicleOfflineVO voo) {
        baseMapper.updateByVin(voo);
    }

    @Override
    public int removeVehicleCarByPlanNo(String planNo) {
        return baseMapper.deleteVehicleCarByPlanNo(planNo);
    }

    @Override
    public List<String> getVinList(VehicleOfflineVO vehicleOfflineVO) {
        return baseMapper.getVinList(vehicleOfflineVO);
    }

    @Override
    public String getMatnrCodeByVin(String vin) {
        return baseMapper.getMatnrCodeByVin(vin);
    }

    @Override
    public PageInfo<VehicleOfflineShareRespVO> queryShareVehicle(VehicleOfflineShareReqVO vo, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<VehicleOfflineShareRespVO> list = baseMapper.queryShareVehicle(vo);
        return new PageInfo<VehicleOfflineShareRespVO>(list);
    }

    @Override
    public void putVehicle(String vin, int hireStatus) {
        Map map = new HashMap();
        map.put("vin",vin);
        map.put("hireStatus",hireStatus);
        baseMapper.putVehicle(map);
    }

    @Override
    public VehicleOffline getByVin(String vin) {
        return baseMapper.getByVin(vin);
    }

    @Override
    public VehicleOfflineVO getVoByVin(String vin) {
        return baseMapper.getVoByVin(vin);
    }
}
